package com.example.springboot_shopsystem01.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.springboot_shopsystem01.domain.Staff;
import com.example.springboot_shopsystem01.domain.Supplier;
import com.example.springboot_shopsystem01.service.StaffService;
import com.example.springboot_shopsystem01.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @GetMapping
    public List<Supplier> getAll(){
        return supplierService.getAll();
    }

    @PostMapping
    public Boolean save(@RequestBody Supplier supplier){  //通过请求体 传json数据过来
        return supplierService.save(supplier);
    }

    @PutMapping
    public Boolean update(@RequestBody Supplier supplier){
        return supplierService.update(supplier);
    }

    @DeleteMapping("{id}")   // 通过路径传参
    public boolean delete(@PathVariable Integer id){
        return supplierService.delete(id);
    }

    @GetMapping("{id}")
    public Supplier getById(@PathVariable Integer id){
        return supplierService.getById(id);
    }

    @GetMapping("{currentPage}/{pageSize}")
    public IPage<Supplier> getPage(@PathVariable int currentPage, @PathVariable int pageSize, Supplier supplier){
        return supplierService.getPage(currentPage, pageSize, supplier);
    }
}
